from flask import request
from flask.views import MethodView

from qingdeng.orms import ArticleORM


class ArticleAPI(MethodView):
    def get(self, article_id):
        page = request.args.get("page", default=1, type=int)
        per_page = request.args.get("per_page", default=10, type=int)

        filters = []

        paginate = (
            ArticleORM.query.order_by(ArticleORM.create_time.asc())
            .filter(*filters)
            .paginate(page=page, per_page=per_page, error_out=False)
        )

        # 接口只返回数据,不返回模板
        article_list = [article.json() for article in paginate.items]
        return {
            "code": 0,
            "msg": "获取数据成功",
            "count": paginate.total,
            "data": article_list,
        }

    def post(self):
        pass

    def put(self, article_id):
        pass

    def delete(self, article_id):
        pass
